package com.customer.controller;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 2 * @Author: xy
 * 3 * @Date: 2021/10/03 下午 12:16:27
 */
public class SendSms {

    public static void main(String[] args) {
        SendSms("18503857095", "123456");

    }

    public static void SendSms(String phone, String code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", " LTAI4G3S7UZyBiRVBu93bcCP",
                "WzDLLmoSEY4VWqrSqSAqnRTonYKNl5");
        /** use STS Token
         DefaultProfile profile = DefaultProfile.getProfile(
         "<your-region-id>",           // The region ID
         "<your-access-key-id>",       // The AccessKey ID of the RAM account
         "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
         "<your-sts-token>");          // STS Token
         **/
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "hopu教育");
        request.putQueryParameter("TemplateCode", "SMS_195860771");
        request.putQueryParameter("TemplateParam", "{'code':'" + code + "'}");

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
